package office.dao.hr;

import java.util.Map;
import platform.common.dao.impl.BaseDomainProviderImpl;
import platform.util.DateUtil;

public class TimingDP extends BaseDomainProviderImpl {
	
	public String getTimingByTrip(){
		String hql = "from Timing where trip.id = ? order by thisDate,type asc";
		return hql;
	}
	
	public String getTimingByDateAndType(){
		String hql = "from Timing where user.id = ? and thisDate = ? and type = ?";
		return hql;
	}
	
	public String getAllTimingByUid(){
		String hql = "from Timing where user.id = ? order by thisDate desc";
		return hql;
	}
	
	public String getAllTimingByUidAndDate(){
		String hql = "from Timing where user.id = ? and thisDate >= ? and thisDate <= ? order by thisDate,type asc";
		return hql;
	}
	
	public String getValidateTiming(){
		String hql = "from Timing where user.id = ? and thisDate = ? and type = ? and trip.id = ?";
		return hql;
	}
	
	public String getAllTimingByDate(){
		String hql = "from Timing where thisDate >= ? and thisDate <= ? order by user.id, thisDate desc";
		return hql;
	}
	
	public String deleteTimingByTripAndDate(Map<String ,Object> condMap){
		StringBuffer stringBuffer = new StringBuffer();
		stringBuffer.append("delete from Timing where trip.id =:tripId and ((1=2) ");
		String thisDate = (String)condMap.get("thisDate");
		if(thisDate.indexOf(" ") != -1){
			String date = thisDate.split(" ")[0];
			String time = thisDate.split(" ")[1];
			if(DateUtil.between(time, "09:01:00", "17:30:00", "HH:mm:ss")){
				stringBuffer.append(" or ( thisDate = '"+date+"' and type = 'pm' ) or (thisDate > '"+date+"') ");
			}else if(DateUtil.compareTo(time, "09:00:00", "HH:mm:ss") <= 0){
				stringBuffer.append(" or ( thisDate >= '"+date+"') ");
			}else if(DateUtil.compareTo(time, "17:30:00", "HH:mm:ss") >= 0){
				stringBuffer.append(" or ( thisDate > '"+date+"') ");
			}
		}
		stringBuffer.append(")");
		return stringBuffer.toString();
	}
	
}
